package com.cn.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.cn.dao.CancelOrderDAO;

public class CancelOrderDAOImpl extends BaseHibernateDAOImpl implements CancelOrderDAO{

	/**
	 * 通过order_id查找对象
	 * @param order_id
	 * @return
	 */
	public Object findByOrder_id(int order_id) {
		try {
			String queryString = "from CancelOrder as co where order_id = " +order_id;
			getSession().beginTransaction();
			Query queryObject = getSession().createQuery(queryString);
			List list = queryObject.list();
			getSession().getTransaction().commit();
			if (list.size() == 0) {
				return null;
			}
			return list.get(0);
		} catch (RuntimeException re) {
			throw re;
		}
	}
	
	/**
	 * 获得时间最久的一条记录
	 * @return
	 */
	public Object getLong() {
		try {
			String queryString = "from CancelOrder as co order by placetime" ;
			getSession().beginTransaction();
			Query queryObject = getSession().createQuery(queryString);
			List list = queryObject.list();
			getSession().getTransaction().commit();
			if (list.size() == 0) {
				return null;
			}
			return list.get(0);
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
